package com.my.test.thread.conditition.old;

public class TestMyQueue {

	static MyQueue<String> myQueue = new MyQueue<String>(10);


	{
		//init();//初始化构造块

		new Thread(() -> {
			while (true) {
				try {
					String s = myQueue.remove();
					System.out.println("消费数据：" + s);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}).start();

	};



	// 模拟生产者线程
	public void init() {
		new Thread(() -> {
			while (true) {
				try {
					String s = myQueue.remove();
					System.out.println("消费数据：" + s);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}).start();

	}

	public void addData(String s) throws InterruptedException {
		myQueue.add(s);
	}

	// 模拟消费者线程
	public static void main(String[] args) throws InterruptedException {
		TestMyQueue t = new TestMyQueue();//初始化的时候会执行构造快
		for (int i = 0; i < 100; i++) {
			//t.addData("data:" + i);
			myQueue.add("data:" + i);
			Thread.sleep(1000);
			System.out.println("生产数据：data:" + i);
		}


	}
}
